//
//  DesignSegment.m
//  ForestPack
//
//  Created by jimmy on 2018/7/9.
//  Copyright © 2018年 郑洲. All rights reserved.
//

#import "DesignSegment.h"

@interface DesignSegment ()

@property(nonatomic,strong)void (^segmentClick)(void);

@end

@implementation DesignSegment

-(void)segmentDidChangedValue
{
    if (_segmentClick) {
        _segmentClick();
    }
}



+ (DesignSegment *)segmentWithClick:(void (^)(void))segmentClick
{
    DesignSegment  * segControl = [[DesignSegment alloc] init];
    
    segControl.segmentClick = segmentClick;
    
    segControl.backgroundColor = RGB_COLOR(238,238,238);
    segControl.selectionStyle = HMSegmentedControlSelectionStyleTextWidthStripe;
    segControl.autoresizingMask = UIViewAutoresizingFlexibleWidth |  UIViewAutoresizingFlexibleRightMargin;
    segControl.titleTextAttributes = @{NSForegroundColorAttributeName:RGB_COLOR(153,153,153),NSFontAttributeName:[UIFont fontWithName:@"PingFangSC-Regular" size:14]};
    //设置选项卡被选中的颜色
    segControl.selectedTitleTextAttributes = @{NSForegroundColorAttributeName:RGB_COLOR(237,34,59),NSFontAttributeName:[UIFont fontWithName:@"PingFangSC-Regular" size:14]};
    segControl.selectionIndicatorLocation = HMSegmentedControlSelectionIndicatorLocationDown;
    segControl.selectionIndicatorHeight = 0;
    //设置开始时默认选中的下标
    segControl.selectedSegmentIndex = 0;
    //设置选中的选项卡的点击事件
    [segControl addTarget:self action:@selector(segmentDidChangedValue) forControlEvents:UIControlEventValueChanged];
        
    return segControl;
}

- (void)setTitlesAry:(NSArray *)titlesAry{
    
    _titlesAry = titlesAry;
    
    self.sectionTitles = titlesAry;
}



@end
